package com.rr.middle;

import java.util.Arrays;

/*
https://leetcode.cn/problems/maximum-number-of-coins-you-can-get/?envType=daily-question&envId=2025-01-22

 */
public class MaxCoins {
    public int maxCoins(int[] piles) {
        int length = piles.length;
        Arrays.sort(piles);
        int startIndex = length / 3;
        int result = 0;
        for (int i = startIndex; i < length; i+=2) {
            result += Math.min(piles[i], piles[i + 1]);
        }
        return result;
    }
}
